<%-- 
    Document   : employee
    Created on : Dec 4, 2011, 11:24:21 PM
    Author     : Michael
--%>

<%@page import="java.sql.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<% session.removeAttribute("UserID"); 
    if(session.getAttribute("Access").equals("Manager"))
    {
        session.setAttribute("EmployeeID", session.getAttribute("ManagerID")); 

    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Employee</title>

<script type="text/javascript">
function ads_clicked()
{
	window.location="AdvertisementList.jsp";
}
function transactions_clicked()
{
	window.location="TransactionList.jsp";
}

function button_updateInfo()
{
    document.employeeInfo.submit();
}

function row_custclick(txt)
{
    document.forms[txt].submit();
}

function row_mousehover(obj)
{
	obj.style.backgroundColor="#6699FF";
}

function row_mouseout(obj)
{
	obj.style.backgroundColor="";
}



</script>
</head>
<body>
<table width="800" border="1">
  <tr>
    <td><img src="Logo.jpg" width="800" height="150" /></td>
  </tr>
  <tr>
  <td>
      <table width="800" border="0" >
          <tr><td><input type="button" value="Home" onclick="window.location='gohome.jsp'"/>&nbsp;
          <input type="button" value="Log Out" onclick="window.location='logout.jsp'"/>&nbsp;
              <input type="button" onclick="window.location='CustomerList.jsp'" value="All Customers" /></td></tr>
      <tr>
        <% if(session.getAttribute("Access").equals("CustomerRep")) { %>  
        <td><button onclick="ads_clicked()">Advertisements</button></td>
        <td><button onclick="transactions_clicked()">Transactions</button></td>
        <td><button onclick="window.location='mailingList.jsp'">Mailing Lists</button></td>
        <td><button onclick="window.location='EmployeeList.jsp'">All Employees</button></td>
        <% }
        if(session.getAttribute("Access").equals("Manager")) { %>     
        <td>
            <h3>Select Report Type: </h3>
            <form name="reporttype" action="SalesReport.jsp" method="post">
                <select name="TYPE">
                    <option value="0">Monthly</option>
                    <option value="1">All Advertisements</option>
                    <option value="2">Transactions</option>
                    <option value="3">Revenue</option>
                    <option value="4">Top Sellers</option>
                    <option value="5">Companies</option>                  
                </select>
                <input type="button" onclick="document.reporttype.submit()" value="Submit" />
            </form>
        </td>
       
        <% } %>

       </tr>
       </table>
    </td>
  </tr>
<tr>
  <td>    
    <table  width="800" border="0">
    <% 
        Connection conn = new DBClasses.GetConnection().getConnection();
        try
        {
           Statement stmt = conn.createStatement();
           String id = "";
           if(session.getAttribute("Access").equals("Manager"))
               id = session.getAttribute("ManagerID").toString();
           else
               id = session.getAttribute("EmployeeID").toString();
               
           String query = "SELECT * FROM employees WHERE EmployeeID='" + id + "'";
           ResultSet rs = stmt.executeQuery(query);
           
           if(!rs.next())
               response.sendRedirect("index.html");
    %>
    <tr>
    <td id="profiletable" align="right" valign="top">
        <label style="padding-right: 100px;"><h3>Your Profile</h3></label><br />
        <form style="padding-right: 10px;" name="employeeInfo" id="employeeInfo" action="employeeInfo.jsp" method="post">
        <label>SSN: </label>
        <input type="text" name="SSN" maxlength="9" value="<%=rs.getInt("SSN")%>" /><br />
        
        <label>First Name: </label> 
        <input type="text" name="FirstName" maxlength="50" value="<%=rs.getString("Firstname")%>" /><br />
        
        <label>Last Name: </label>
        <input type="text" name="LastName" maxlength="50" value="<%=rs.getString("Lastname")%>" /><br />
        
        <label>Address: </label>
        <input type="text" name="Address" maxlength="100" value="<%=rs.getString("Address")%>" /><br />
        
        <label>City: </label>
        <input type="text" name="City" maxlength="20" value="<%=rs.getString("City")%>" /><br />
        
        <label>State: </label>
        <input type="text" name="State" maxlength="2" value="<%=rs.getString("State")%>" /><br />
        
        <label>Zip: </label>
        <input type="text" name="ZipCode" maxlength="5" value="<%=rs.getString("ZipCode")%>" /><br />
        
        <label>Telephone: </label>
        <input type="text" name="Telephone" maxlength="10" value="<%=rs.getString("Telephone")%>" /><br />
        
        <label>Start Date: </label>
        <input type="text" name="StartDate" readonly="readonly" value="<%=rs.getString("StartDate")%>" /><br />
        
        <label>Hourly Rate: </label>
        <input type="text" name="HourlyRate" <% if(session.getAttribute("Access").equals("CustomerRep")) { %> readonly="readonly" <%}%> value="<%=rs.getInt("HourlyRate")%>" /><br />
        
        <input type="button" value="Update Info" onclick="return button_updateInfo()" />
        </form>
    </td>

        <% 
                }
        catch(Exception e) { e.printStackTrace(); }
        finally
        {
            try {
            conn.close(); }
            catch(Exception e) {}
        }
        %>
        
<% if(session.getAttribute("Access").equals("CustomerRep")) { %>
   <td valign="top" align="center">
        <label><h3>All Customers</h3></label><br />
        <table border="1" > 

            <tr>
                    <td >First Name</td>
                    <td >Last Name</td>
                    <td >Email</td>
            </tr>
            <% 
                conn = null;
                try
                {
                    conn = new DBClasses.GetConnection().getConnection();
                    String query = "SELECT * FROM Customer ORDER BY Email";

                    java.sql.Statement stmt = conn.createStatement();
                    java.sql.ResultSet rs = stmt.executeQuery(query);

                    int i=0;
                    while(rs.next())
                    {

            %>
            <tr onclick="row_custclick('<%="cust" + i %>')" onmouseout="row_mouseout(this)" onmouseover="row_mousehover(this)">
            <form name="<%="cust" + i %>" action="CustomerClicked.jsp" method="post">
            <input name="CUST" type="hidden" value="<%=rs.getInt("CustomerID")%>" />
            <td width="167"><%=rs.getString("Firstname")%></td>
            <td width="167"><%=rs.getString("Lastname")%></td>
            <td width="166"><%=rs.getString("Email")%></td>
            </form>
            </tr>
            <%
                            i++;
                       }
               }
               catch(Exception e)
               {
                   e.printStackTrace();
               }

               finally
               {
                   try{
                   conn.close(); }
                   catch(Exception e) {
                       e.printStackTrace();
                   }
               }
            %>
            </table>
   </td>
            
<% }
   else {
%>
       <td valign="top" align="center">
        <label><h3>All Employees</h3></label><br />
        <table border="1" > 

            <tr>
                    <td >Last Name</td>
                    <td >First Name</td>
                    <td >SSN</td>
            </tr>
            <% 
                conn = null;
                try
                {
                    conn = new DBClasses.GetConnection().getConnection();
                    String query = "SELECT * FROM employees ORDER BY LastName";

                    java.sql.Statement stmt = conn.createStatement();
                    java.sql.ResultSet rs = stmt.executeQuery(query);

                    int i=0;
                    while(rs.next())
                    {
                        if(!rs.getString("EmployeeID").equals(session.getAttribute("ManagerID")))
                                                       {

            %>
            <tr onclick="row_custclick('<%="emp" + i %>')" onmouseout="row_mouseout(this)" onmouseover="row_mousehover(this)">
            <form name="<%="emp" + i %>" action="EmployeeClicked.jsp" method="post">
            <input name="EMP" type="hidden" value="<%=rs.getInt("EmployeeID")%>" />
            <td width="167"><%=rs.getString("LastName")%></td>
            <td width="167"><%=rs.getString("FirstName")%></td>
            <td width="166"><%=rs.getString("SSN")%></td>
            </form>
            </tr>
            <%
                       }
                            i++;
                       }
               }
               catch(Exception e)
               {
                   e.printStackTrace();
               }

               finally
               {
                   try{
                   conn.close(); }
                   catch(Exception e) {
                       e.printStackTrace();
                   }
               }
            %>
            </table>
   </td>
            
            
             <%  } %>
        </tr>
        </table>
        </td>
    </tr>
</table>
</body>
</html>
